function prt_plot()
{
  var selectedGraphElement = document.getElementById ("prt_selectedGraph").value;
  var url = "php/VehicleInfo.php/" + selectedVehicleId + "/currentTime/" + selectedGraphElement;

  if(selectedGraphElement != "")
  {
    var graphObject;
    var xAx;
    var yAx;
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open("GET",url,false);
    xmlhttp.send();
    var json = xmlhttp.responseText; 
    var obj = JSON.parse(json);
    graphObject = obj.data;
    xAx = obj.xAxis;
    yAx = obj.yAxis;
    plotGraph('#prt_stats', xAx, yAx, graphObject);
  }
  else
  {
    $('#prt_stats').empty();
  }
}

function station_plot()
{
  var selectedStation = document.getElementById ("station_selectedStation").value;
  var selectedGraph = document.getElementById ("station_selectedGraph").value;

  if(selectedGraph != "")
  {
    var graphObject;
    var xAx;
    var yAx;
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    var url = "php/Stations.php/" + selectedStation + "/" + selectedGraph;

    xmlhttp.open("GET",url,false);
    xmlhttp.send();
    var json = xmlhttp.responseText;
    var obj = JSON.parse(json);
    graphObject = obj.data;
    xAx = obj.xAxis;
    yAx = obj.yAxis;
    plotGraph('#station_stats', xAx, yAx, graphObject);
  }
  else
  {
    $('#station_stats').empty();
  }
}

function plotGraph(whereToPlot, xAx, yAx, graphData)
{
  elem = $(whereToPlot);

  $.plot(
    elem,
    [{label: xAx + "/" + yAx,  data: graphData}],
    {
      lines: {show: true},
      points: {show: true},
      grid:
      {
        backgroundColor: { colors: ["#fff", "#eee"] }
      }
    }
  );
}